package com.k7.mobile.platform.web.action.admin;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.k7.mobile.platform.dataobject.BanIpDO;
import com.k7.mobile.platform.web.action.BaseAction;

/**
 * IP后台管理
 * @author
 *
 */
public class BanIpManageAction extends BaseAction{
	

	/**
	 * 
	 */
	private static final long serialVersionUID = -2763613763882108344L;

	private String queryStr;
	private String ip;
	private Long id;
	private Date banTime ;
	private Integer page;
	
	private List<BanIpDO> list;
	
	private BanIpDO queryDO;
	
	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}


	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public Date getBanTime() {
		return banTime;
	}

	public void setBanTime(Date banTime) {
		this.banTime = banTime;
	}

	public BanIpDO getQueryDO() {
		return queryDO;
	}

	public void setQueryDO(BanIpDO quertyDO) {
		this.queryDO = queryDO;
	}

	public List<BanIpDO> getList() {
		return list;
	}


	public String getQueryStr() {
		return queryStr;
	}

	public void setQueryStr(String queryStr) {
		this.queryStr = queryStr;
	}

	/**
	 * IP列表页
	 * @return
	 * @throws Exception
	 */
	public String list() throws Exception{
//		User user = super.getUser();
//		if(user==null){
//			return null;
//		}
		queryDO = new BanIpDO();
		
		if(queryStr!= null)
			queryDO.setIp(queryStr);
		//设置分页
		if(page == null)
			page = 1;
		queryDO.setToPage(page);
		list = super.getBanIpBO().findList(queryDO);
		
		return SUCCESS;
	}
	
	/**
	 * 新增ip
	 * @return
	 * @throws Exception
	 */
	public String add() throws Exception{
//		User user = super.getUser();
//		if(user==null){
//			return null;
//		}
		BanIpDO banIpDO= new BanIpDO();
		if(ip!= null)
			banIpDO.setIp(ip);
		if(banTime!= null)
			banIpDO.setBanTime(banTime);
		banIpDO.setCreateUserId(0L);
		super.getBanIpBO().add(banIpDO);
		return SUCCESS;
	}
	/**
	 * 删除IP
	 * @return
	 * @throws Exception
	 */
	public String del() throws Exception{
//		User user = super.getUser();
//		if(user==null){
//			return null;
//		}
		BanIpDO banIpDO= new BanIpDO();
		
		if(id!= null)
			banIpDO.setId(id);
		if(banTime!= null)
			banIpDO.setBanTime(banTime);
		//设置分页
		
		super.getBanIpBO().delete(banIpDO);
		return SUCCESS;
	}
	
}
